<script>
	import {
		HTTP_REQUEST_URL
	} from './config/app';
	export default {
		globalData: {
			spid: 0,
			code: 0,
			isLogin: false,
			userInfo: {},
			MyMenus: [],
			appId: "wx48b3ec0b640e512f", //小程序ID
			merId: 22, //商户ID
			bottomLift: 0,
			imgLoadBG: 'https://italytao.oss-cn-shanghai.aliyuncs.com/H5Static/images/xunwuMorenBG.png', // 图片未加载完成显示的图片
			wxCode: "https://italytao.oss-cn-shanghai.aliyuncs.com/H5Static/images/xunwuWXcode.jpeg", // 微信名片图片
		},
		onLaunch: function(option) {
			const accountInfo = uni.getAccountInfoSync();
			console.log(accountInfo.miniProgram.appId); // 小程序 appId
			let that = this;
			// #ifdef MP
			if (HTTP_REQUEST_URL == '') {
				console.error(
					"请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
				);
				return false;
			}
			// #endif
			// 获取导航高度；
			uni.getSystemInfo({
				success: function(res) {
					that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
				}
			});
			that.getDeviceSize().then(res => {
			    const {bottomLift} = res
			    that.globalData.bottomLift = bottomLift
			})
			
			// 检测更新
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				if (res.hasUpdate) {
					updateManager.onUpdateReady(function(res2) {
						uni.showModal({
							title: '更新提示',
							content: '发现新版本，是否重启应用?',
							cancelColor: '#eeeeee',
							confirmColor: '#333333',
							success(res2) {
								if (res2.confirm) {
									// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
									updateManager.applyUpdate();
								}
							}
						});
					});
				}
			});

			updateManager.onUpdateFailed(function(res) {
				// 新的版本下载失败
				uni.showModal({
					title: '提示',
					content: '检查到有新版本，但下载失败，请检查网络设置',
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});
		},
		onShow(option) {
			console.log(option, "首页onshow")
			// 橙子支付返回
			if (option.referrerInfo && JSON.stringify(option.referrerInfo) != "{}" && option.scene == 1038) {
				if ((option.path == "pages/order_confirm/index" && option.referrerInfo.extraData.userOrderNum) || (option
						.path == "pages/order_details/index" && option.referrerInfo.extraData.userOrderNum)) {
					uni.redirectTo({
						url: '/pages/order_details/index?order_id=' + option.referrerInfo.extraData.userOrderNum
					})
				}
			}
		},
		onHide: function() {

		},
		methods: {
			// 获取设备信息
			getDeviceSize: function() {
				return new Promise((resolve, reject) => {
					wx.getSystemInfo({
						success: function(res) {
							// console.log(res)
							const {
								screenHeight,
								safeArea
							} = res
							const {
								bottom
							} = safeArea
							const bottomLift = screenHeight - bottom
							resolve({
								bottomLift
							})
						}
					})
				})
			},
		},
	}
</script>
<style lang="scss">
	@import "uview-ui/index.scss";
</style>
<style>
	@import url("@/plugin/animate/animate.min.css");
	@import 'static/css/base.css';
	@import 'static/iconfont/iconfont.css';
	@import 'static/css/guildford.css';
	@import 'static/css/style.scss';

	view {
		box-sizing: border-box;
	}

	.bg-color-red {
		background-color: #e93323 !important;
	}

	.syspadding {
		padding-top: var(--status-bar-height);
	}

	.flex {
		display: flex;
	}

	.uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none
	}

	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}

	uni-checkbox .uni-checkbox-input,
	uni-radio .uni-radio-input {
		border-radius: 0 !important;
		border: 1px solid rgba(204, 204, 204, 1) !important;
	}

	uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked,
	uni-radio .uni-radio-input.uni-radio-input-checked {
		border: 1rpx solid rgba(0, 0, 0, 1) !important;
		background-color: rgba(0, 0, 0, 1) !important;
	}

	uni-checkbox .uni-checkbox-wrapper,
	uni-radio .uni-radio-wrapper {
		width: 100%;
	}

	uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before,
	uni-radio .uni-radio-input.uni-radio-input-checked:before {
		color: #FFFFFF;
	}

	uni-checkbox:not([disabled]) .uni-checkbox-input:hover,
	uni-radio:not([disabled]) .uni-radio-input:hover {
		border-color: transparent;
	}
</style>
